package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.domain.CraftProgram;
import com.uwlaser.service.CraftProgramService;
import com.uwlaser.service.dto.CraftProgramDto;
import com.uwlaser.service.dto.CraftProgramQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author zk-Qin
* @date 2022-05-26
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "产品程序号管理")
@RequestMapping("/api/craftProgram")
public class CraftProgramController {

    private final CraftProgramService craftProgramService;

    @GetMapping
    @Log("查询产品程序号")
    @ApiOperation("查询产品程序号")
    @PreAuthorize("@el.check('craftProgram:list')")
    public ResponseEntity query(CraftProgramQueryParam query, Pageable pageable){
        return new ResponseEntity<>(craftProgramService.queryAll(query,pageable),HttpStatus.OK);
    }

    @GetMapping("/list")
    @Log("查询产品程序号")
    @ApiOperation("查询产品程序号")
    @PreAuthorize("@el.check('craftProgram:list')")
    public ResponseEntity list(CraftProgramQueryParam query){
        return new ResponseEntity<>(craftProgramService.queryAll(query),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增产品程序号")
    @ApiOperation("新增产品程序号")
    @PreAuthorize("@el.check('craftProgram:add')")
    public ResponseEntity create(@Validated @RequestBody CraftProgramDto resources){
        return new ResponseEntity<>(craftProgramService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改产品程序号")
    @ApiOperation("修改产品程序号")
    @PreAuthorize("@el.check('craftProgram:edit')")
    public ResponseEntity update(@Validated @RequestBody CraftProgramDto resources){
        craftProgramService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除产品程序号")
    @ApiOperation("删除产品程序号")
    @PreAuthorize("@el.check('craftProgram:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        craftProgramService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出产品程序号")
    @ApiOperation("导出产品程序号")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('craftProgram:list')")
    public void download(HttpServletResponse response, CraftProgramQueryParam query) throws IOException {
        craftProgramService.download(craftProgramService.queryAll(query), response);
    }*/

}
